package dk.dashboardFP.utils {
	import flash.utils.describeType;

	/**
	 * @author josef
	 */
	public class StringUtils {
		public static function get_sObjectName(oTarget : Object) : String {
			
			if (!oTarget) return "null";
			
			var objectDescription : XML = describeType(oTarget);

			var typeString : String = objectDescription.@name.toString();
			
			var isDynamic : Boolean = false;
			if (objectDescription.@isDynamic == "true") {
				//return "Object";
				isDynamic = true;
			}
			
			//DFPLogger.log("return type :: " + typeString+" isDynamic :: " + isDynamic);
			
			if (typeString.indexOf("::") != -1) {
				var returnString : String = typeString.split("::")[1];
				return returnString; 
			} else {
				if (typeString == "Array" && isDynamic) {
					return "Object";
				}
				return typeString;
			}
			
			
			if (typeof(oTarget) != "object") {
				return typeof(oTarget);
			} else if (oTarget is Array) {
				if (isDynamic) {
					return "Object";
				}
				return "Array";
			} else if (oTarget is XMLList) {
				return "XMLList";
			} else if (oTarget is XML) {
				return "XML";
			}
			
			var sObjectName : String = oTarget.toString();
			return sObjectName.slice(sObjectName.indexOf(" ") + 1, sObjectName.indexOf("]"));
		}
	}
}
